/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package client.dal;

import client.entity.Category;
import java.util.ArrayList;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import util.HibernateUtil;

/**
 *
 * @author mrlucky
 */
public class CategoryDAL {

    public CategoryDAL() {
    }
    
    public ArrayList<Category> listCate() {
        SessionFactory sf = HibernateUtil.getSessionFactory();
        Session ss = sf.openSession();
        ss.beginTransaction().begin();
        ArrayList<Category> list = (ArrayList<Category>) ss.createQuery("from Category c").list();
        ss.beginTransaction().commit();
        ss.close();
        return list;
    }
    
    public ArrayList<String> loadCateNameByRecId(String recId)
    {
        SessionFactory sf = HibernateUtil.getSessionFactory();
        Session ss = sf.openSession();
        ss.beginTransaction().begin();
        ArrayList<String> list = (ArrayList<String>) ss.createQuery("select c.categoryName from Category c inner join RecruitmentCategory rc on c.id = rc.category.id inner join Recruitment r on r.id = rc.recruitment.id where r.id = 3").list();
        ss.beginTransaction().commit();
        ss.close();
        return list;
    }
}
